package com.j283_5.wisdom_park.controller.car_management;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.j283_5.wisdom_park.common.result.ResultData;
import com.j283_5.wisdom_park.pojo.CarInformation;
import com.j283_5.wisdom_park.pojo.Visitors;
import com.j283_5.wisdom_park.service.CarInformationService;
import com.j283_5.wisdom_park.vo.car_management.CarInformationVo;
import com.j283_5.wisdom_park.vo.car_management.CarRecordVo;
import com.j283_5.wisdom_park.vo.car_management.CarVo;
import com.j283_5.wisdom_park.vo.car_management.FindCarVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 蒋翔
 * @since 2022-04-29
 */
@RestController
@RequestMapping("/car")
@Api(value = "车辆信息管理",tags = "车辆信息管理",produces="蒋翔")
public class CarController {
    @Resource
    private CarInformationService carInformationService;


    @RequestMapping(value = "/carInformationList" , method = RequestMethod.GET)
    @ApiOperation(value = "查询所有车辆信息",notes = "查询所有车辆信息（分页）",produces="蒋翔", response = ResultData.class)
    public ResultData carInformationList(@Param("page") Page<CarInformation> page, @Param("findCarVo") FindCarVo findCarVo){
//        List<CarInformationVo> carInformationVoList = new ArrayList<>();
//        CarInformationVo carInformationVo1 = new CarInformationVo(1, "张勋", "18767256412", "豫A00FX2", "丰田2020款 2.5L 无级 尊贵版", 1
//                , new Timestamp(System.currentTimeMillis()), new Timestamp(System.currentTimeMillis()));
//        CarInformationVo carInformationVo2 = new CarInformationVo(2, "李君虞", "13208432854", "浙A88888", "阿斯顿·马丁2012款 6.0L 手自一体",  1
//                );
//        carInformationVoList.add(carInformationVo1);
//        carInformationVoList.add(carInformationVo2);
//        return ResultData.ok().data(carInformationVoList);

        System.out.println("===");
        return carInformationService.carInformationList(page,findCarVo);
    }


    @RequestMapping(value = "/findOneCar" , method = RequestMethod.POST)
    @ApiOperation(value = "查询车辆详细信息",notes = "查询车辆详细信息",produces="蒋翔", response = ResultData.class)
    public ResultData findOneCar(Integer cinfId){
//        CarRecordVo carRecord1 = new CarRecordVo("豫A00FX2","包月车","出场",new Timestamp(System.currentTimeMillis()));
//        CarRecordVo carRecord2 = new CarRecordVo("豫A00FX2","包月车","入场",new Timestamp(System.currentTimeMillis()));
//        ArrayList<CarRecordVo> carRecords = new ArrayList<>();
//        carRecords.add(carRecord1);
//        carRecords.add(carRecord2);
//        CarVo carVo = new CarVo("张晓萌", "13786578901", "男", "杭州久拓咨询有限公司", "A1幢", "502", "人脸图片", "包月车",
//                "豫A00FX2", "丰田", "2020款 2.5L 无级 尊贵版", new Timestamp(System.currentTimeMillis()), new Timestamp(System.currentTimeMillis()), carRecords);
        return carInformationService.findOneCar(cinfId);
    }

    @RequestMapping(value = "/addCarInformation" , method = RequestMethod.POST)
    @ApiOperation(value = "添加车辆详细信息",notes = "添加车辆详细信息",produces="蒋翔", response = ResultData.class)
    public ResultData addCarInformation(@PathParam("carVo") CarVo carVo){
        return carInformationService.addVisitors(carVo);
        //return ResultData.ok().message("添加成功！");
    }

    @RequestMapping(value = "/deleteCarInformation" , method = RequestMethod.POST)
    @ApiOperation(value = "删除车辆详细信息",notes = "删除车辆详细信息（可批量）",produces="蒋翔", response = ResultData.class)
    public ResultData deleteCarInformation(@RequestBody ArrayList<Integer> cinfIdList){
//        return ResultData.ok().message("删除成功！");
        return carInformationService.deleteVisitors(cinfIdList);
    }

    @RequestMapping(value = "/findCarOwner" , method = RequestMethod.POST)
    @ApiOperation(value = "查询车主信息",notes = "查询车主信息",produces="蒋翔", response = ResultData.class)
    public ResultData findCarOwner(String ownerName , String ownerType){
        return carInformationService.findCarOwner(ownerName ,ownerType);
    }


}

